qualifier_attr
Procedural macro attributes for adding "qualifiers" to various items.
At the moment, the crate supports the following "qualifiers":
pub
,pub(crate)
, etc. - visibility and restrictiondefault
- default implementations (a feature of specialization)async
- asynchronous code, e.g.async fn
unsafe
- unsafe code, e.g.unsafe fn
,unsafe trait
const
- code that may run at compile time, e.g.const fn
extern "ABI"
- specifying an ABI, e.g.extern "C" fn
Limitations
- It seems that rust-analyzer will sometimes complain when the attribute is used with modules.
Examples
extern crate qualifier_attr;
// We can add a qualifier to a function
// with an attribute.
const CONST_RES: u32 = const_fn;
// It's not so impressive on its own,
// but with `cfg_attr`, it can be conditional.
// It even works with types, imports, and more!
use Foo;
// Traits and implementations too!?
// You can add qualifiers to the fields of a
// struct as well with this special attribute.
;
Learn more about cfg_attr
here.
Note on legacy attributes
Before version 0.2.0, this crate provided a separate attribute for each kind of item. While this should generally be a small win for compile times, it is generally not justified by the additional complexity. The legacy attributes are still available behind the default legacy_attrs
feature flag, but their use is currently discouraged. In order to disable the legacy attributes, add the following to your Cargo.toml
:
[]
= { = "0.2", = false }